#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n, m;
	cout << "input the number of n and m: ";
	cin >> n >> m;
	vector < bool> a(n+1, 1);
	int k = n, j = 0;
	int i = 1;
	for ( i = 1; i <= n+1; i++)
	{
		if (i == n + 1)
			i = (n + 1) % n;
		if (a[i] == 1)
			j++;
		if (j == m)
		{
			j = 0;
			k--;
			a[i] = 0;
		}
		 
		if (k == 1)
			break;
	}
	for (int t = 1; t <= n; t++)
		if (a[t] == 1)
			cout << t << endl;

	return 0;
}